/*
 * @Author: zhao.dp
 * @Date: 2022-08-30 09:26:25
 * @LastEditors: zhao.dp
 * @LastEditTime: 2022-08-31 15:58:07
 * @Description:
 */
import { getFolder } from '../util/get-folder.mjs'
import { mkdirActionHelper } from '../util/mkdir-action-helper.mjs'

export default {
  description: '创建组件',
  prompts: [
    {
      type: 'list',
      name: 'path',
      message: '请选择组件创建目录',
      choices: getFolder('src/components'),
    },
    {
      type: 'input',
      name: 'name',
      message: '请输入文件名(去除扩展名)',
      validate: (v) => {
        if (!v || v.trim === '') {
          return '文件名不能为空'
        } else if (v == 'list' || v == 'detail') {
          return 'list 和 detail 为保留关键字，无法直接创建，请通过创建标准模块进行生成'
        } else {
          return true
        }
      },
    },
    {
      type: 'confirm',
      name: 'mkdir',
      message: '是否创建文件夹',
      default: true,
    },
  ],
  actions: (data) => {
    const { targetDir, actions } = mkdirActionHelper(data)
    actions.push({
      type: 'add',
      path: `${targetDir}/{{name}}.vue`,
      templateFile: 'dev-kit/plop-templates/component/index.hbs',
    })
    return actions
  },
}
